<?php
// The source code packaged with this file is Free Software, Copyright (C) 2005 by
// Ricardo Galli <gallir at uib dot es>.
// It's licensed under the AFFERO GENERAL PUBLIC LICENSE unless stated otherwise.
// You can get copies of the licenses here:
// 		http://www.affero.org/oagpl.html
// AFFERO GENERAL PUBLIC LICENSE is also included in the file called "COPYING".
// -------------------------------------------------------------------------------------

include_once('Smarty.class.php');
$main_smarty = new Smarty;

include_once('config.php');
include_once(mnminclude.'html1.php');
include_once(mnminclude.'link.php');
include_once(mnminclude.'tags.php');
include_once(mnminclude.'search.php');
include_once(mnminclude.'smartyvariables.php');

// -------------------------------------------------------------------------------------

global $the_template, $main_smarty, $db;



	echo "<div class=tlb><span><a onclick=\"new Effect.toggle('latcomments','blind', {queue: 'end'}); \">  <img src=\"".my_base_url.my_pligg_base."/templates/" . $the_template . "/images/expand.png\" /></a></span><a href=\"".getmyurl("comments")."\">".$main_smarty->get_config_vars('PLIGG_Visual_Latest_Comments')."</a></div><div id=latcomments>";

	$res = "select comment_content,comment_id,link_id from ".table_comments.",".table_links." WHERE comment_link_id = link_id ORDER BY comment_date DESC limit ".comments_size_sidebar."";
	$list_comments = mysql_query($res) or die(mysql_error());

		while($row = mysql_fetch_array($list_comments)){			
			$story_url = getmyurl("story", $row['link_id']);			
			echo "<a class='switchurl' href='".$story_url."#c".$row['comment_id']."'>".ShortenText(save_text_to_html($row['comment_content']))."</a>";			
		}

echo '<li class="rmore"><a href='.getmyurl("comments").'>'.$main_smarty->get_config_vars("PLIGG_Visual_What_Is_Pligg_Read_More").'</a></li>';
echo "</div>";


// determine the amount of characters to show for each comment	
function ShortenText($text) {
	$chars = comments_length_sidebar;

  $text = $text." ";
  $text = substr($text,0,$chars);
  $text = substr($text,0,strrpos($text,' '));
  $text = $text."...";

  return $text;
  }		
	
?>
